package com.cn.web.controller.Report;

import com.alibaba.fastjson2.JSONObject;
import com.cn.bean.vo.Report.ItemReport;
import com.cn.bean.vo.Report.PartsList;
import com.cn.service.server.Report.ItemReportServer;
import com.cn.service.server.Report.PartsListServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/Par")
@Transactional
public class PartsListController {

    private final PartsListServer partsListServer;

    @Autowired(required = false)
    public PartsListController(PartsListServer partsListServer) {
        this.partsListServer = partsListServer;
    }

    @RequestMapping("/select/PartsList")
    @ResponseBody
    public List<PartsList> selectItemPartsList(@RequestBody JSONObject jsonObject) {
        Integer page = jsonObject.getInteger("page");
        Integer limit = jsonObject.getInteger("limit");
        String structureName = jsonObject.getString("structureName");
        String componentName = jsonObject.getString("componentName");
        String consumableCategoryName = jsonObject.getString("consumableCategoryName");
        String specification = jsonObject.getString("specification");
        String model = jsonObject.getString("model");
        String processName = jsonObject.getString("processName");
        structureName = (structureName != null) ? structureName : "";
        componentName = (componentName != null) ? componentName : "";
        consumableCategoryName = (consumableCategoryName != null) ? consumableCategoryName : "";
        specification = (specification != null) ? specification : "";
        model = (model != null) ? model : "";
        processName = (processName != null) ? processName : "";
        return partsListServer.selectItemPartsList(limit, page,structureName,componentName,consumableCategoryName,specification,model,processName);
    }
}
